package edu.hebeu.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import edu.hebeu.R;
import edu.hebeu.entity.OrderDetailResponse;

public class OrderDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<OrderDetailResponse.OrderDetail> data;

    public OrderDetailAdapter(List<OrderDetailResponse.OrderDetail> data) {
        this.data = data;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_order_detail, null);
        return new InnerHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ((InnerHolder) holder).setData(data.get(position));

    }

    @Override
    public int getItemCount() {
        if (data != null) {
            return data.size();
        }
        return 0;
    }

    public class InnerHolder extends RecyclerView.ViewHolder {

        private TextView tv_good_name;
        private TextView tv_good_price;
        private TextView tv_good_buy_count;
        private TextView tv_good_total_money;
        private TextView tv_code;

        private OrderDetailResponse.OrderDetail orderDetail;

        public InnerHolder(@NonNull View itemView) {
            super(itemView);
            tv_good_name = (TextView) itemView.findViewById(R.id.tv_good_name);
            tv_good_price = (TextView) itemView.findViewById(R.id.tv_good_price);
            tv_good_buy_count = (TextView) itemView.findViewById(R.id.tv_good_buy_count);
            tv_good_total_money = (TextView) itemView.findViewById(R.id.tv_good_total_money);
            tv_code = (TextView) itemView.findViewById(R.id.tv_code);
        }

        public void setData(OrderDetailResponse.OrderDetail orderDetail) {
            this.orderDetail = orderDetail;

            tv_good_name.setText("商品：" + orderDetail.getName());
            tv_good_price.setText("单价：￥" + orderDetail.getGoodsprice());
            tv_good_buy_count.setText("购买数量：" + orderDetail.getGoodscount());
            tv_good_total_money.setText("商品小计：￥" + orderDetail.getPrice());
            tv_code.setText("所属订单：" + orderDetail.getOrder_code());
        }
    }
}
